// pages/index/group/addCard/addCard.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    disabled: true,
    tel:null,
    forwardImg:[],
    backImg:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      tel:options.tel
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },
  /**
   * 身份证上传
   */
  uploads(res){
    console.log(res)
    if (res.currentTarget.id == "forwardImg"){
      this.data.forwardImg = res.detail.fileList.map(item => {
        return item.url
      })
    } else if (res.currentTarget.id == "backImg"){
      this.data.backImg = res.detail.fileList.map(item => {
        return item.url
      })
    }
    if (this.data.forwardImg.length > 0 && this.data.backImg.length > 0) {
      this.setData({
        disabled: false
      })
    } else {
      this.setData({
        disabled: true
      })
    }
  },
  /**
   * 提交信息
   */
  submitInfo(){
    app.globalData.request("get","applet/tenant_manage/tenantAdd",{
      tenant_tel: this.data.tel,
      tenant_front: this.data.forwardImg[0],
      tenant_back: this.data.backImg[0],
      tenant_agent: wx.getStorageSync("id")
    })
    .then(res => {
      wx.navigateBack({
        delta:2
      })
    }).catch(err => {
      wx.showToast({
        title: err.msg,
        icon:"none"
      })
    })
  }
})